/*
* @Author: xfy
* @Date:   2017-08-24 11:53:40
* @Last Modified by:   xfy
* @Last Modified time: 2017-09-15 13:48:28
*/
'use strict';
require('./index.css')
require('page/common/nav/index.js');
require('page/common/header/index.js');
require('util/slider/index.js');
var navSide         = require('page/common/nav-side/index.js');
var templateBanner  = require('./banner.string');
var _supper         = require('util/supper.js');
var _product        = require('service/product-service.js');
var templateFloor   = require('./floor.string');

$(function() {
    //渲染banner的html
    var bannerHtml = _supper.renderHtml(templateBanner);
    $('.banner-con').html(bannerHtml);
    //初始化banner
    var $slider = $('.banner').unslider({
        dots : true
    });
    //前一张和后一张操作的时件绑定
    $('.banner-con .banner-arrow').click(function(){
        var forward = $(this).hasClass('prev') ? 'prev' : 'next';
        $slider.data('unslider')[forward]();
    });

    //渲染floor
    loadFloor(1, '小吃');
    loadFloor(2, '主食');
    loadFloor(3, '海鲜');
    loadFloor(4, '汉堡薯条');
    loadFloor(5, '酒水饮料');
});

function loadFloor(categoryId, categoryName){
    _product.getProductList({
        pageNum     : 1,
        pageSize    : 5,
        categoryId  : categoryId
    }, function(res){
        res.categoryName    = categoryName;
        var listHtml        = _supper.renderHtml(templateFloor, res);
        $('.index.w').append(listHtml);
    }, function(errMsg){
        $('.order-body').html('<div class="error-tip"><p class="error-msg"><i class="fa fa-coffee"></i> 出错了哦…</p></div>');
    });
};